package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.entity.OrderSetting;
import com.itheima.health.pojo.result.Result;
import com.itheima.health.service.ReservationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ordersetting")
@Slf4j
public class ReservationController {
    @Autowired
    private ReservationService reservationService;

    /**
     * 预约管理上传文件_当月预约设置
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result ordersetting(@RequestParam("excelFile") MultipartFile file) {
        log.info("预约管理上传文件_当月预约设置:{}", file);
        reservationService.processExcelFile(file);
        return new Result(true, MessageConst.IMPORT_ORDERSETTING_SUCCESS);
    }

    /**
     * 当月预约信息展示
     *
     * @param year
     * @param month
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(String year, String month) {
        log.info("当月预约信息展示:{}-{}", year, month);
        List<Map<String, Object>> orderSettingDTOList = reservationService.getOrderSettingByMonth(year, month);
        return new Result(true, MessageConst.GET_ORDERSETTING_SUCCESS, orderSettingDTOList);
    }

    /**
     * 预约管理可预约单独设置
     * @param orderSetting
     * @return
     */
    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting) {
        log.info("预约管理可预约单独设置 :{}",orderSetting);
        reservationService.editNumberByDate(orderSetting);
        return new Result(true,MessageConst.ORDERSETTING_SUCCESS);
    }
}
